<template>
	<view class="container">
		<view class="tab-seaction">
			<template v-for="tab in serviceNavList" :key="tab.id">
				<view :class="{ 'tab-item':true, 'tab-item__actived': activeName === tab.id }"
					@click="setActiveName(tab.id)">
					<text>{{ tab.parentName }}</text>
				</view>
			</template>
		</view>
		<view class="content-seaction">
			<s-changeClothes v-if="activeName === 1" :currentNavInfo="currentNav" />
			<s-highCustomize v-else-if="activeName === 2" :currentNavInfo="currentNav" />
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed } from "vue"
	import { listServiceNav } from "@/api/http/followHeartService"
	import { Service } from "@/api/types/Service"

	let activeName = ref<number>(1)
	// 传递当前被激活的tab配置项供mainService使用
	let currentNav = computed(() : Service.globalNavType =>
		(serviceNavList?.value || []).find(item => item.id === activeName.value) || { id: 1, parentName: '无痕改衣' }
	)
	const setActiveName = (active : number) => {
		activeName.value = active
	}

	let serviceNavList = ref<Service.globalNavType[]>()
	const getServiceNavList = async () => {
		let data = await listServiceNav()
		serviceNavList.value = data || []
	}
	onMounted(async () => {
		await getServiceNavList()
	})
	// 定义分享给朋友的行为
	const onShareAppMessage = () => {
		return {
			title: '随心改-让改衣更随心', // 分享标题
			imageUrl: 'https://www.sxg123.cn/share.png', // 分享图片地址
		}
	}
	// 定义分享到朋友圈的行为
	const onShareTimeline = () => {
		return {
			title: '随心改-让改衣更随心', // 分享标题
			imageUrl: 'https://www.sxg123.cn/share.png', // 分享图片地址
		}
	}
</script>

<style scoped lang="scss">
	.container {
		.tab-seaction {
			position: fixed;
			top: 1;           /* 固定在页面顶部 */
			left: 50%;
			transform: translateX(-50%);
			@include flex;
			align-items: center;
			width: 100%;
			height: 80rpx;
			background-color: #fff; /* 背景色设置为白色，避免背景透明造成的显示问题 */

			&:after {
				position: absolute;
				bottom: 0;
				content: "";
				width: 100%;
				height: 2rpx;
				background: #cccfd3;
			}

			z-index: 2;

			.tab-item {
				position: relative;
				padding: 0 10rpx;
				padding-bottom: 10rpx;
				font-size: 31rpx;
				color: $uni-base-color;
				height: 60rpx;              /* 与 tab-seaction 的高度一致 */
				line-height: 60rpx;        /* 设置行高为容器的高度，使文本垂直居中 */
				text-align: center;//水平方向居中对齐
				font-weight: bold; /* 或者可以设置为 400, 500, 700 等数值，来调整字体的粗细 */
			}

			// 激活tab后的样式
			.tab-item__actived {
				color: $uni-primary;

				&:after {
					position: absolute;
					left: 50%;
					transform: translateX(-50%);
					bottom: 0;
					content: "";
					width: 80rpx;
					height: 5rpx;
					background: $uni-primary;
					z-index: 3;
				}
			}
		}

		.content-seaction {
			margin-top: 70rpx;
			width: 100%;
			height: calc(100vh - 70rpx);
		}
	}
</style>